package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.RentalHouse;
import com.ruoyi.business.service.IRentalHouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出租房源Controller
 * 
 * @author asher
 * @date 2021-12-02
 */
@RestController
@RequestMapping("/business/rental_house")
public class RentalHouseController extends BaseController
{
    @Autowired
    private IRentalHouseService rentalHouseService;

    /**
     * 查询出租房源列表
     */
    @PreAuthorize("@ss.hasPermi('business:rental_house:list')")
    @GetMapping("/list")
    public TableDataInfo list(RentalHouse rentalHouse)
    {
        startPage();
        List<RentalHouse> list = rentalHouseService.selectRentalHouseList(rentalHouse);
        return getDataTable(list);
    }

    /**
     * 导出出租房源列表
     */
    @PreAuthorize("@ss.hasPermi('business:rental_house:export')")
    @Log(title = "出租房源", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RentalHouse rentalHouse)
    {
        List<RentalHouse> list = rentalHouseService.selectRentalHouseList(rentalHouse);
        ExcelUtil<RentalHouse> util = new ExcelUtil<RentalHouse>(RentalHouse.class);
        return util.exportExcel(list, "出租房源数据");
    }

    /**
     * 获取出租房源详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:rental_house:query')")
    @GetMapping(value = "/{rentalHouseId}")
    public AjaxResult getInfo(@PathVariable("rentalHouseId") Long rentalHouseId)
    {
        return AjaxResult.success(rentalHouseService.selectRentalHouseByRentalHouseId(rentalHouseId));
    }

    /**
     * 新增出租房源
     */
    @PreAuthorize("@ss.hasPermi('business:rental_house:add')")
    @Log(title = "出租房源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RentalHouse rentalHouse)
    {
        return toAjax(rentalHouseService.insertRentalHouse(rentalHouse));
    }

    /**
     * 修改出租房源
     */
    @PreAuthorize("@ss.hasPermi('business:rental_house:edit')")
    @Log(title = "出租房源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RentalHouse rentalHouse)
    {
        return toAjax(rentalHouseService.updateRentalHouse(rentalHouse));
    }

    /**
     * 删除出租房源
     */
    @PreAuthorize("@ss.hasPermi('business:rental_house:remove')")
    @Log(title = "出租房源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rentalHouseIds}")
    public AjaxResult remove(@PathVariable Long[] rentalHouseIds)
    {
        return toAjax(rentalHouseService.deleteRentalHouseByRentalHouseIds(rentalHouseIds));
    }
}
